#!/usr/bin/env node
const inquirer = require("inquirer");
const { inquirerConfig } = require("../../config");
const mkDir = require("../mkDir");
const updatePackage = require("../updatePackage");
const { log } = require("../utils");
const t = require("../../config/dict");
const configLang = require("../configLang");

module.exports = (cmd, options) => {
  configLang({ lang: "english", name: cmd || "mfoApp" }, (context) => {
    console.log("");
    log("tip", {
      message: [
        "1)",
        t(context.lang, "设置项目"),
        context.name,
        t(context.lang, "配置"),
        t(context.lang, "。"),
      ].join(" "),
    });
    inquirer
      .prompt([...inquirerConfig(context)])
      .then((answers) => {
        context = {
          ...context,
          metadata: {
            projectTypeConfig: {
              updatePackage: true,
              dependencies: false,
              ui: false,
              vaild: false,
              qiankun: false,
            },
            ...answers,
          },
          taskType: "initPackage",
        };
        return context;
      })
      .then((context) => {
        return mkDir(context);
      })
      .then((context) => {
        return updatePackage(context);
      })
      .then((context) => {
        log("success", {
          message: [
            t(context.lang, "初始化"),
            "package.json",
            t(context.lang, "完成"),
            t(context.lang, "。"),
          ].join(" "),
        });
      });
  });
};
